package service

import (
	"blog/dao"
	"blog/model"
)

var ArticleService = &articleService{}

type articleService struct {
}

func (service *articleService) GetArticle(id interface{}) *ArticleDTO {
	article, _ := dao.ArticleDao.ArticleGet(id)
	articleExtend, _ := dao.ArticleExtendDao.ArticleExtendGet(id)
	articleExtend.BrowseNum = articleExtend.BrowseNum + 1
	_ = dao.ArticleExtendDao.ArticleExtendUpdate(articleExtend)
	topic, _ := dao.TopicDao.TopicGet(article.TopicId)
	return &ArticleDTO{
		Article:       article,
		ArticleExtend: articleExtend,
		Topic:         topic,
	}
}

type ArticleDTO struct {
	*model.Article
	ArticleExtend *model.ArticleExtend `json:"articleExtend"`
	Topic         *model.Topic         `json:"topic"`
}

type ArticleListDTO struct {
}
